const router = require('koa-router')()
const Mock = require('mockjs')

const { list } = Mock.mock({
  "list|10000": [{
    "id": "@id",
    "image|4-10": ["@image(150x120, @color, item)"],
    "title": "@ctitle",
    "address": "@county(true)",
    "desc": "@cword(10, 20)",
    "price|1-100": 1,
    "sell|1000-100000": 1,
    "score": "@float(0,4, 1, 1)",
  }]
})

// 列表
router.get('/list', ctx => {
  const { pageSize = 10, pageCode = 1 } = ctx.request.query;
  // 分页
  const newList = list.slice((pageCode - 1) * pageSize, pageSize * pageCode)

  ctx.body = {
    code: 200,
    data: newList
  }
})

// 详情
router.get('/detail', ctx => {
  const { id } = ctx.request.query;
  const item = list.find(v => v.id === id);
  ctx.body = {
    code: 200,
    data: item
  }
})

module.exports = router
